package com.bluecoffee.rest;

import com.bluecoffee.domain.Book;
import com.bluecoffee.service.BookService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by qianlong on 2016/12/19.
 */
@RestController
@Configuration
@EnableAutoConfiguration
public class BookController {

    private static final Logger logger = Logger.getLogger(BookController.class);

    @Autowired
    private BookService bookService;

    @RequestMapping(value = "/books", method = RequestMethod.POST, produces = "application/json")
    public ResultJson createBook(@RequestBody Book book){
        return bookService.addBook(book);
    }

    @RequestMapping(value = "/books", method = RequestMethod.GET, produces = "application/json")
    public List<Book> listAllBook(){
        logger.info("--------listAllBook---------");
        return bookService.listBook(new Book());
    }
}
